define(function (require, exports, module) {
    return function (jQuery) {
        (function ($) {
            /*seajs-content-start*/
            var sparkStreamParaCtrl = function ($scope, httpservice){
            	
            	 $scope.grid1 = {
                         gridpagedata:{
                             nowpage:1,
                             totalpage:1,
                             totalcount:10,
                             startline:1,
                             endline:10,
                             pagesize:10,
                             datacount:10,
                             pagelist:[10,20,30,50,100],
                             toFirstpage: function(){
                            	 
                                 $scope.grid1.gridpagedata.nowpage = 1;
                                 $scope.turnPage();
                             },
                             toToppage: function(){
                                 if($scope.grid1.gridpagedata.nowpage>1){
                                     $scope.grid1.gridpagedata.nowpage--;
                                 }
                                 $scope.turnPage();
                             },
                             toNextpage: function(){
                                 if($scope.grid1.gridpagedata.nowpage<$scope.grid1.gridpagedata.totalpage){
                                     $scope.grid1.gridpagedata.nowpage++;
                                 }
                                 $scope.turnPage();
                             },
                             toLastpage: function(){
                                 $scope.grid1.gridpagedata.nowpage = $scope.grid1.gridpagedata.totalpage;
                                 $scope.turnPage();
                             },
                             topage: function(){
                                 if($scope.grid1.gridpagedata.nowpage<1){
                                     $scope.grid1.gridpagedata.nowpage = 1;
                                 }
                                 if($scope.grid1.gridpagedata.nowpage>$scope.grid1.gridpagedata.totalpage){
                                     $scope.grid1.gridpagedata.nowpage = $scope.grid1.gridpagedata.totalpage;
                                 }
                                 $scope.turnPage();
                             },
                             changePagesize: function(){
                                 $scope.grid1.gridpagedata.nowpage = 1;
                                 $scope.turnPage();
                             }
                         },
                         griddata: {
                             colnames: ['编号','功能',"功能编码",'参数名称','参数编码','参数值','参数类型','参数说明',"操作"],
                             colmodel: [
                                 { name: 'no', index: 'no', sortable: false, sorttype: 'number', align:"center"},
                                 { name: 'funcName', index: 'funcName', sortable: false, align:"center"},
                                 { name: 'funcCode', index: 'funcCode', sortable: false, align:"center"},
                                 { name: 'paraName', index: 'paraName', sortable: true, sorttype: 'number', align:"center"},
                                 { name: 'paraCode', index: 'paraCode', sortable: true, sorttype: 'number', align:"center"},
                                 { name: 'paraValue', index: 'paraValue', sortable: true, sorttype: 'number',align:"center"},
                                 { name: 'paraType', index: 'paraType', sortable: true, sorttype: 'number', align:"center"},
                                 { name: 'paraComment', index: 'paraComment', sortable: true, sorttype: 'number', align:"center"},
                                 { name: 'operation', index: 'operation', sortable: true, sorttype: 'number', align:"center"},
     
                             ],
                             data: [
//                                 { loginId: "1",loginCode: "YH111",psw: "111", state: "", nickname:"张三", "department":"研发部", "email": "123456789@qq.com",mobile:"18812345678", role:"系统管理员"},
 //                                { loginId: "1",loginCode: "YH111",psw: "111", state: "", nickname:"张三", "department":"研发部", "email": "123456789@qq.com",mobile:"18812345678"}
//                                 { loginId: "1",loginCode: "YH111",psw: "111", state: "", nickname:"张三", "department":"研发部", "email": "123456789@qq.com",mobile:"18812345678", role:"系统管理员"},
//                                 { loginId: "1",loginCode: "YH111",psw: "111", state: "", nickname:"张三", "department":"研发部", "email": "123456789@qq.com",mobile:"18812345678", role:"系统管理员"},
//                                 { loginId: "1",loginCode: "YH111",psw: "111", state: "", nickname:"张三", "department":"研发部", "email": "123456789@qq.com",mobile:"18812345678", role:"系统管理员"},
//                                 { loginId: "1",loginCode: "YH111",psw: "111", state: "", nickname:"张三", "department":"研发部", "email": "123456789@qq.com",mobile:"18812345678", role:"系统管理员"},
//                                 { loginId: "1",loginCode: "YH111",psw: "111", state: "", nickname:"张三", "department":"研发部", "email": "123456789@qq.com",mobile:"18812345678", role:"系统管理员"},
//                                 { loginId: "1",loginCode: "YH111",psw: "111", state: "", nickname:"张三", "department":"研发部", "email": "123456789@qq.com",mobile:"18812345678", role:"系统管理员"},
//                                 { loginId: "1",loginCode: "YH111",psw: "111", state: "", nickname:"张三", "department":"研发部", "email": "123456789@qq.com",mobile:"18812345678", role:"系统管理员"},
//                                 { loginId: "1",loginCode: "YH111",psw: "111", state: "", nickname:"张三", "department":"研发部", "email": "123456789@qq.com",mobile:"18812345678", role:"系统管理员"},
//                                 { loginId: "1",loginCode: "YH111",psw: "111", state: "", nickname:"张三", "department":"研发部", "email": "123456789@qq.com",mobile:"18812345678", role:"系统管理员"},
//                                 { loginId: "1",loginCode: "YH111",psw: "111", state: "", nickname:"张三", "department":"研发部", "email": "123456789@qq.com",mobile:"18812345678", role:"系统管理员"},
//                                 { loginId: "1",loginCode: "YH111",psw: "111", state: "", nickname:"张三", "department":"研发部", "email": "123456789@qq.com",mobile:"18812345678", role:"系统管理员"},
//                                 { loginId: "1",loginCode: "YH111",psw: "111", state: "", nickname:"张三", "department":"研发部", "email": "123456789@qq.com",mobile:"18812345678", role:"系统管理员"},
//                                 { loginId: "1",loginCode: "YH111",psw: "111", state: "", nickname:"张三", "department":"研发部", "email": "123456789@qq.com",mobile:"18812345678", role:"系统管理员"},
//                                 { loginId: "1",loginCode: "YH111",psw: "111", state: "", nickname:"张三", "department":"研发部", "email": "123456789@qq.com",mobile:"18812345678", role:"系统管理员"}
                             ]
                         },
                         obj:{},
                         shrinkToFit:true,
                         gridresize: function (grid) {
                             grid.setGridWidth($(window).width());
                             grid.setGridHeight(400);
                         }
                     };
            	 
            	 $scope.turnPage=function(){
            		
            		
            		$scope.query();
            	 }
            	 
            	 
            	 $scope.query=function(){
            		
            		 var param={
            				funcName:$("#queryName1").val(),
            				paraName:$("#queryName2").val(),
            				paraCode:$("#queryName3").val(),
            				pageindex:$scope.grid1.gridpagedata.nowpage,
            				pagesize:$scope.grid1.gridpagedata.pagesize
            		 };
            		 
           		 
            		 $.post("/SpkPara/query",param,function(result){
            			 $scope.grid1.gridpagedata.totalcount = result.recordCount;
                         $scope.grid1.gridpagedata.totalpage = result.pageCount;
                         $scope.grid1.gridpagedata.startline =result.startLine;
                         $scope.grid1.gridpagedata.endline = result.endLine;
                         $scope.grid1.gridpagedata.datacount = result.dataCount;
                         
                        
                         $scope.grid1.griddata.data = result.datas;
                         for(var i=0;i<result.datas.length;i++){
                        	 $scope.grid1.griddata.data[i].no=i+1;
                        	 var t=result.datas[i].paraType;
                			 var t1=null;
                			 if(t=='D'){
                				 t1='日期';
                				 
                			 }else if(t=='N'){
                				 t1='数字';
                			 }else {
                				 t1='字符串';
                			 }
                			 $scope.grid1.griddata.data[i].paraType=t1;
                        	 var id2="{funcCode:\""+result.datas[i].funcCode+"\" , paraCode:\""+result.datas[i].paraCode+"\"}";
                        	 
                        	 
                        	 $scope.grid1.griddata.data[i].operation="<input value='删除' class='del' name='"+ id2+"' type='button' />  <input value='修改' class='mod' type='button' name='"+id2+"' />";
                         }
                         $scope.$apply();
            		 });
            		 
            		
            		 
           	 }
            	 $scope.user2 = {
                         title: "修改参数",
                         show: function () { },
                         ok: function () { },
                         cancel: function () { }
                 };
            	 
            	 $(".mod").live('click',function(){
            		 var param=$(this).attr("name");
            		 var j=eval('('+param+')');
            		 $.post("/SpkPara/getByKey",j,function(data){
            			 $("#funcName2").val(data.funcName);
            			 $("#funcCode2").val(data.funcCode);
            			 $("#paraName2").val(data.paraName);
            			 $("#paraCode2").val(data.paraCode);
            			
            			 var t=data.paraType;
            			
            			 var t1=null;
            			 if(t=='D'){
            				 t1='日期';
            				 
            			 }else if(t=='N'){
            				 t1='数字';
            			 }else {
            				 t1='字符串';
            			 }
            			 $("#paraType2").val(t1);
            			 $("#paraComment2").val(data.paraComment);
            			 $("#operNo2").val(data.operNo);
            			 
            			
            			 
                 		if( data.paraType=='D'  ){
                 			$("#paraValue2").remove();
                 			$("#abcd").after('<input id="paraValue2" placeholder="请输入日期" class="laydate-icon" value="" onclick="laydate()">');
                 			$("#paraValue2").attr("value",data.paraValue);
                 		}else if(data.paraType=='N'){
                 			$("#paraValue2").remove();
                 			$("#abcd").after('<input  id="paraValue2" value="" />');
                 			$("#paraValue2").attr("value",data.paraValue);
                 		}else {
                 			$("#paraValue2").remove();
                 			$("#abcd").after('<textarea rows="10" cols="42" id="paraValue2" value="" />');
                 			$("#paraValue2").attr("value",data.paraValue);
                 		}
            			 
            			 
            		 })
                     
                     $scope.visible = true;
                     $scope.user2.title = "修改参数";
                     $scope.user2.show();
                     $scope.user2.ok = function (){

                    	 if($("#funcName2").val()==''){
                    		 alert("功能名称不能空");
                    		 return ;
                    	 }
                    	 if($("#funcCode2").val()==''){
                    		 alert("功能编码不能空");
                    		 return ;
                    	 }
                    	 if($("#paraName2").val()==''){
                    		 alert("参数名不能空");
                    		 return ;
                    	 }
                    	 if($("#paraValue2").val()==''){
                    		 alert("参数值不能空");
                    		 return ;
                    	 }
                    	 if($("#paraCode2").val()==''){
                    		 alert("参数编码不能空");
                    		 return ;
                    	 }
                    	 if($("#paraType2").val()==''){
                    		 alert("参数类型不能空");
                    		 return ;
                    	 }
                    	
                    	 var t=$("#paraType2").val();
                    	 if(t=="数字"){
                     		t='N';
                     	}else if(t=="字符串"){
                     		t='C';
                     	}else {
                     		t='D';
                     	}
                    	 
                    	 param={
                    		funcName:$("#funcName2").val(),
                    	 	funcCode:$("#funcCode2").val(),
                    	 	paraName:$("#paraName2").val(),
                    	 	paraCode:$("#paraCode2").val(),
                    	 	paraValue:$("#paraValue2").val(),
                    	 	paraType:t,
                    	 	paraComment:$("#paraComment2").val(),
                    	 	operNo:$("#operNo2").val()
                    	 };
                    	 
                    	 $.post("/SpkPara/modify",param,function(data){
                    		 if(data>0){
                    			 alert("修改成功")
                    			 $("#paraValue2").remove();
                    			
                    			 $scope.query();
                    		 }else{
                    			 alert("修改失败")
                    			 $("#paraValue2").remove();
                    		 }
                    		 
                    	 })
                    	
                     }
                 
            		 
            	 })
            
            	 $(".del").live('click',function(){
            		 var r=confirm("确定删除记录?");
            		 if(r==true){
	            		 var param=$(this).attr("name");
	            		 var j=eval('('+param+')');
	            		 $.post("/SpkPara/del",j,function(data){
	            			if(data==1){
	            				alert("删除成功")
	            				$scope.query();
	            			}else{
	            				alert("删除失败")
	            			}
	            		 })
            		 }
            	 })
            	 $("#paraType").live('change',function(){
            		var type=$(this).val();
            		if($("#paraValue")){
            			$("#paraValue").remove();
            		}
            		
            		if(type=='日期'){
            			$("#abc").after('<input id="paraValue" placeholder="请输入日期" class="laydate-icon" onclick="laydate()">');
            		}else if(type=='数字'){
            			$("#abc").after(" <input id='paraValue' value='' />");
            		}else {
            			$("#abc").after(" <textarea rows=10 cols=42 id='paraValue' />");
            		}
            	 })
            	 
            	  $("#paraType2").live('change',function(){
            		var type=$(this).val();
            		if($("#paraValue2")){
            			$("#paraValue2").remove();
            		}
            		
            		if(type=='日期'){
            			$("#abcd").after('<input id="paraValue2" placeholder="请输入日期" class="laydate-icon" onclick="laydate()">');
            		}else if(type=='数字'){
            			$("#abcd").after("<input id='paraValue2' value='' />");
            		}else {
            			$("#abcd").after("<textarea rows=10 cols=42 id='paraValue2' />");
            		}
            	 })
            	 
            
            	 
            	 var clean = function(){
            		
                     $("#funcName").val("");
                     $("#funcCode").val("");
                     $("#paraName").val("");
                     $("#paraCode").val("");
                     $("#paraValue").remove();
                     $("#paraType").val("");
                     $("#operNo").val("");
                     $("#paraComment").val("");
                     
                    
                 };
                 
                 
                 var vf=function(){
                	 if($("#funcName").val()==''){
                		 alert("功能名称不能空");
                		 return false;
                	 }
                	 if($("#funcCode").val()==''){
                		 alert("功能编码不能空");
                		 return false;
                	 }
                	 if($("#paraName").val()==''){
                		 alert("参数名不能空");
                		 return false;
                	 }
                	 if($("#paraValue").val()==''){
                		 alert("参数值不能空");
                		 return false;
                	 }
                	 if($("#paraCode").val()==''){
                		 alert("参数编码不能空");
                		 return false;
                	 }
                	 if($("#paraType").val()==''){
                		 alert("参数类型不能空");
                		 return false;
                	 }
                	 return true;
                 }
            	
            	  $scope.user = {
                          title: "新增参数",
                          show: function () { },
                          ok: function () { },
                          cancel: function () { }
                  };
                 $scope.newUser = function (){
                  
                     $scope.visible = true;
                     $scope.user.title = "新增参数";
                     $scope.user.show();
                     $scope.user.ok = function (){
                    	if(!vf()){
                    		
                    		return;
                    	}
                    	
                    	var t=$("#paraType").val();
                    	if(t=="数字"){
                    		var v=$("#paraValue").val();
                    		if(isNaN(v)){
                    			alert("参数类型与参数值不匹配")
                    			return ;
                    		}
                    	}
                    	
                    	if(t=="数字"){
                    		t='N';
                    	}else if(t=="字符串"){
                    		t='C';
                    	}else {
                    		t='D';
                    	}
                    	 
                    	 
                    	 param={
                    		funcName:$("#funcName").val(),
                    	 	funcCode:$("#funcCode").val(),
                    	 	paraName:$("#paraName").val(),
                    	 	paraCode:$("#paraCode").val(),
                    	 	paraValue:$("#paraValue").val(),
                    	 	paraType:t,
                    	 	operNo:$("#operNo").val(),
                    	 	paraComment:$("#paraComment").val()
                    	 	
                    	 };
                    	$.post("/SpkPara/insert",param,function(data){
                    		if(data==0){
                    			alert("参数已存在")
                    		}else if(data==1){
                    			alert("插入成功")
                    			clean();
                    			$scope.query();
                    		}else{
                    			alert("插入失败")
                    		}
                    	})
                     }
                 };
            	 
            	
            	
            	
            	
            	
            	
            };
            angular.module('sparkStreamPara-ctrl', [])
                .controller('SparkStreamParaCtrl', ['$scope', 'HttpService', sparkStreamParaCtrl])
           
        })(jQuery);
    }
});